using System;
using NUnit.Framework;

namespace NUnitTestFixture
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	[TestFixture] 
	public class GrooveV12HelpersTestFixture
	{
		GrooveWebServicesV12Helpers.Context Context;
		GrooveWebServicesV12Helpers.Account Account;
		GrooveWebServicesV12Helpers.Identity Identity;
		string SpaceURI;
		GrooveWebServicesV12Helpers.Space Space;
		GrooveWebServicesV12Helpers.Tool CalendarTool;
		GrooveWebServicesV12Helpers.Files.FilesTool FilesTool;
		GrooveWebServicesV12Helpers.Tool DiscussionTool;

		public GrooveV12HelpersTestFixture()
		{
		}

		/// <summary>
		/// Setup the Accounts array so you've got something to work with
		/// </summary>
		[TestFixtureSetUp] public void InitFixture() 
		{
			GrooveWebServicesV12Helpers.Account[] Accounts;
			GrooveWebServicesV12Helpers.Identity[] Identities;

			Context = new GrooveWebServicesV12Helpers.Context();
			Assert.IsNotNull(Context, "Null Context");

			try
			{
				Accounts = GrooveWebServicesV12Helpers.Account.GetAccounts(Context);
				Assert.IsTrue(Accounts.Length >= 1, "No Accounts found");
				Account = Accounts[0];
				Console.WriteLine("Account Name=" + Account.Name);

				Identities = Account.Identities;
				Assert.IsTrue(Identities.Length >= 1, "No Identities found");
				Identity = Identities[0];
				Console.WriteLine("Identity Name=" + Identity.Name);

				SpaceURI = Identity.CreateSpace(String.Format("NUnitTestSpace-{0}", DateTime.Now.ToShortTimeString()), "", "");
				Assert.IsNotNull(SpaceURI, "Space could not be created");

				Space = Identity.OpenSpace(SpaceURI);
				Assert.IsNotNull(Space, "Could not open test space");
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message);
			}
		}

		/// <summary>
		/// Setup the Accounts array so you've got something to work with
		/// </summary>
		[TestFixtureTearDown] public void TermFixture() 
		{
			Identity.DeleteSpace(SpaceURI, true, true);
		}

		/// <summary>
		/// 
		/// </summary>
		[Test()]
		public void Test_01_CreateTools() 
		{
			System.Collections.Hashtable h = new System.Collections.Hashtable();

			GrooveWebServicesV12Helpers.ToolTemplate[] ToolTemplates = Space.ToolTemplates;
			foreach (GrooveWebServicesV12Helpers.ToolTemplate ToolTemplate in ToolTemplates)
			{
				string ToolTemplateOutput = 
					"<ToolTemplate " +
					"Name='" + CommandUtils.UtilStatic.XMLEncode(ToolTemplate.Name) + "' " +
					"Author='" + CommandUtils.UtilStatic.XMLEncode(ToolTemplate.Author) + "' " +
					"Category='" + CommandUtils.UtilStatic.XMLEncode(ToolTemplate.Category) + "' " +
					"ComponentResourceURL='" + CommandUtils.UtilStatic.XMLEncode(ToolTemplate.ComponentResourceURL) + "' " +
					"Description='" + CommandUtils.UtilStatic.XMLEncode(ToolTemplate.Description) + "' " +
					"ID='" + CommandUtils.UtilStatic.XMLEncode(ToolTemplate.ID) + "' " +
					"LongName='" + CommandUtils.UtilStatic.XMLEncode(ToolTemplate.LongName) + "' " +
					"Type='" + CommandUtils.UtilStatic.XMLEncode(ToolTemplate.Type) + "' " +
					"/>";

				Console.WriteLine(ToolTemplateOutput);
				h.Add(ToolTemplate.Name, ToolTemplate.ComponentResourceURL);
			}

			string calendarToolURI = Space.AddTool("Calendar", (string) h["Calendar"]);
			Assert.IsNotNull(calendarToolURI, "calendarToolURI is null");
			CalendarTool = Space.OpenTool(calendarToolURI);
			Assert.IsNotNull(CalendarTool, "CalendarTool is null");

			string filesToolURI = Space.AddTool("Files", (string) h["Files"]);
			Assert.IsNotNull(filesToolURI, "filesToolURI is null");
			FilesTool = (GrooveWebServicesV12Helpers.Files.FilesTool) Space.OpenTool(filesToolURI);
			Assert.IsNotNull(FilesTool, "FilesTool is null");
			
			string discussionToolURI = Space.AddTool("Discussion", (string) h["Discussion"]);
			Assert.IsNotNull(discussionToolURI, "discussionToolURI is null");
			DiscussionTool = Space.OpenTool(discussionToolURI);
			Assert.IsNotNull(DiscussionTool, "DiscussionTool is null");
		}

		/// <summary>
		/// 
		/// </summary>
		[Test()]
		public void Test_02_IterateToolsInWorkspace() 
		{
			Console.WriteLine("");
			Console.WriteLine("Account");
			Console.WriteLine("  Name: " + Account.Name);
			Console.WriteLine("  URI: " + Account.URI);
			Console.WriteLine("  BindableURL: " + Account.BindableURL);

			Console.WriteLine("");
			Console.WriteLine("  Identity");
			Console.WriteLine("    Name: " + Identity.Name);
			Console.WriteLine("    URI: " + Identity.URI);
			Console.WriteLine("    BindableURL: " + Identity.BindableURL);

			Console.WriteLine("");
			Console.WriteLine("    Space");
			Console.WriteLine("      Name: " + Space.Name);
			Console.WriteLine("      URI: " + Space.URI);
			Console.WriteLine("      BindableURL: " + Space.BindableURL);

			GrooveWebServicesV12Helpers.Member[] Members = Space.Members;
			foreach (GrooveWebServicesV12Helpers.Member Member in Members)
			{
				Console.WriteLine("");
				Console.WriteLine("      Member");
				Console.WriteLine("        Name: " + Member.Name);
				Console.WriteLine("        URI: " + Member.URI);
				Console.WriteLine("        BindableURL: " + Member.BindableURL);
			}

			GrooveWebServicesV12Helpers.Tool[] Tools = Space.Tools;
			foreach (GrooveWebServicesV12Helpers.Tool Tool in Tools)
			{
				Console.WriteLine("");
				Console.WriteLine("      Tool");
				Console.WriteLine("        Name: " + Tool.Name);
				Console.WriteLine("        URI: " + Tool.URI);
				Console.WriteLine("        ID: " + Tool.ID);
				Console.WriteLine("        BindableURL: " + Tool.BindableURL);
			}
		}

		[Test()]
		public void Test_03_BindToolsInWorkspace()
		{
			//  Bind tests
			GrooveWebServicesV12Helpers.Account BindTestAccount = Account;
			GrooveWebServicesV12Helpers.Identity BindTestIdentity = Identity;
			GrooveWebServicesV12Helpers.Contact BindTestContact = BindTestAccount.PersonalContacts[0];
			GrooveWebServicesV12Helpers.Space BindTestSpace = BindTestIdentity.StandardSpaces[0];

			GrooveWebServicesV12Helpers.Account BoundAccount = (GrooveWebServicesV12Helpers.Account)GrooveWebServicesV12Helpers.BindServices.Bind
				(
				BindTestAccount.BindableURL,
				Context
				);

			GrooveWebServicesV12Helpers.Identity BoundIdentity = (GrooveWebServicesV12Helpers.Identity)GrooveWebServicesV12Helpers.BindServices.Bind
				(
				BindTestIdentity.BindableURL,
				Context
				);

			GrooveWebServicesV12Helpers.Contact BoundContact = (GrooveWebServicesV12Helpers.Contact)GrooveWebServicesV12Helpers.BindServices.Bind
				(
				BindTestContact.BindableURL,
				Context
				);

			GrooveWebServicesV12Helpers.Space BoundSpace = (GrooveWebServicesV12Helpers.Space)GrooveWebServicesV12Helpers.BindServices.Bind
				(
				BindTestSpace.BindableURL,
				Context
				);

			for (int i=0; i<BindTestSpace.Tools.Length; i++)
			{
				GrooveWebServicesV12Helpers.Tool BindTestTool = BindTestSpace.Tools[i];

				GrooveWebServicesV12Helpers.Tool BoundTool = (GrooveWebServicesV12Helpers.Tool)GrooveWebServicesV12Helpers.BindServices.Bind
					(
					BindTestTool.BindableURL,
					Context
					);

				Console.WriteLine("");
				Console.WriteLine("      Bound Tool");
				Console.WriteLine("        Name: " + BoundTool.Name);
				Console.WriteLine("        URI: " + BoundTool.URI);
				Console.WriteLine("        ID: " + BoundTool.ID);
				Console.WriteLine("        BindableURL: " + BoundTool.BindableURL);
                Console.WriteLine("        Type: " + BoundTool.Type);

				object BoundToolEntry = null;
                switch (BoundTool.Type)
                {
                    case GrooveWebServicesV12Helpers.Shared.GROOVE_CALENDAR_TOOL_SUPPORTED_TYPE:
                        {
                            GrooveWebServicesV12Helpers.Calendar.CalendarTool CalendarTool = (GrooveWebServicesV12Helpers.Calendar.CalendarTool)BoundTool;
                            GrooveWebServicesV12Helpers.Calendar.CalendarEntry[] CalendarEntries = CalendarTool.CalendarEntries;

                            if (CalendarEntries.Length != 0)
                            {
                                BoundToolEntry = GrooveWebServicesV12Helpers.BindServices.Bind
                                    (
                                    CalendarEntries[0].BindableURL,
                                    Context
                                    );
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine("No calendar entries to test binding!");
                            }
                            break;
                        }
                    case GrooveWebServicesV12Helpers.Shared.GROOVE_DISCUSSION_TOOL_SUPPORTED_TYPE:
                        {
                            GrooveWebServicesV12Helpers.Discussion.DiscussionTool DiscussionTool = (GrooveWebServicesV12Helpers.Discussion.DiscussionTool)BoundTool;
                            GrooveWebServicesV12Helpers.Discussion.DiscussionEntry[] DiscussionEntries = DiscussionTool.DiscussionEntries;

                            if (DiscussionEntries.Length != 0)
                            {
                                BoundToolEntry = GrooveWebServicesV12Helpers.BindServices.Bind
                                    (
                                    DiscussionEntries[0].BindableURL,
                                    Context
                                    );
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine("No discussion entries to test binding!");
                            }
                            break;
                        }
                    case GrooveWebServicesV12Helpers.Shared.GROOVE_FILES_TOOL_SUPPORTED_TYPE:
                        {
                            GrooveWebServicesV12Helpers.Files.FilesTool FilesTool = (GrooveWebServicesV12Helpers.Files.FilesTool)BoundTool;
                            GrooveWebServicesV12Helpers.Files.Folder RootFolder = FilesTool.RootFolder;
                            GrooveWebServicesV12Helpers.Files.File[] Files = RootFolder.Files;

                            if (Files.Length != 0)
                            {
                                BoundToolEntry = GrooveWebServicesV12Helpers.BindServices.Bind
                                    (
                                    Files[0].BindableURL,
                                    Context
                                    );
                            }
                            else
                                System.Diagnostics.Debug.WriteLine("No files to test binding!");

                            GrooveWebServicesV12Helpers.Files.Folder[] Folders = RootFolder.Folders;

                            if (Folders.Length != 0)
                            {
                                BoundToolEntry = GrooveWebServicesV12Helpers.BindServices.Bind
                                    (
                                    Folders[0].BindableURL,
                                    Context
                                    );
                            }
                            else
                                System.Diagnostics.Debug.WriteLine("No folders to test binding!");
                            break;
                        }
                    case GrooveWebServicesV12Helpers.Shared.GROOVE_FORMS_TOOL_SUPPORTED_TYPE:
                        {
                            GrooveWebServicesV12Helpers.Forms.FormsTool FormsTool = (GrooveWebServicesV12Helpers.Forms.FormsTool)BoundTool;
                            GrooveWebServicesV12Helpers.Forms.Form[] Forms = FormsTool.Forms;

                            BoundToolEntry = GrooveWebServicesV12Helpers.BindServices.Bind
                                (
                                Forms[0].BindableURL,
                                Context
                                );

                            GrooveWebServicesV12Helpers.Forms.Field[] Fields = Forms[0].Fields;
                            BoundToolEntry = GrooveWebServicesV12Helpers.BindServices.Bind
                                (
                                Fields[0].BindableURL,
                                Context
                                );

                            GrooveWebServicesV12Helpers.Forms.View[] Views = FormsTool.Views;
                            BoundToolEntry = GrooveWebServicesV12Helpers.BindServices.Bind
                                (
                                Views[0].BindableURL,
                                Context
                                );
                            break;
                        }
                    case GrooveWebServicesV12Helpers.Shared.GROOVE_FORMS2_TOOL_SUPPORTED_TYPE:
                        {
                            GrooveWebServicesV12Helpers.Forms2.FormsTool FormsTool = (GrooveWebServicesV12Helpers.Forms2.FormsTool)BoundTool;
                            GrooveWebServicesV12Helpers.Forms2.Form[] Forms = FormsTool.Forms;

                            BoundToolEntry = GrooveWebServicesV12Helpers.BindServices.Bind
                                (
                                Forms[0].BindableURL,
                                Context
                                );

                            GrooveWebServicesV12Helpers.Forms2.Field[] Fields = Forms[0].Fields;
                            BoundToolEntry = GrooveWebServicesV12Helpers.BindServices.Bind
                                (
                                Fields[0].BindableURL,
                                Context
                                );

                            GrooveWebServicesV12Helpers.Forms2.View[] Views = FormsTool.Views;
                            BoundToolEntry = GrooveWebServicesV12Helpers.BindServices.Bind
                                (
                                Views[0].BindableURL,
                                Context
                                );
                            break;
                        }
                    default:
                        throw new System.Exception("Unknown tool type!");
                }
            }
		}

        [Test()]
        [Description("File.Update fails with SOAP exception")]
        public void Test_04_FileUpdateTest()
        {
            GrooveWebServicesV12Helpers.ToolTemplate[] ToolTemplates = Space.ToolTemplates;

            GrooveWebServicesV12Helpers.ToolTemplate filesToolTemplate = null;
            foreach (GrooveWebServicesV12Helpers.ToolTemplate tt in ToolTemplates)
            {
                if (tt.Name == "Files")
                {
                    filesToolTemplate = tt;
                    break;
                }
            }

            Assert.IsNotNull(filesToolTemplate, "Null filesToolTemplate");
            string tmpFilesToolURI = Space.AddTool("Test File Update", filesToolTemplate);
            GrooveWebServicesV12Helpers.Files.FilesTool tmpFilesTool = (GrooveWebServicesV12Helpers.Files.FilesTool)Space.OpenTool(tmpFilesToolURI);

            string FileName = "Testing.txt";
            string FileDisplayName = "Testing";

            byte[] contents = { (byte)'a', (byte)'b', (byte)'c', (byte)'d' };
            string fileURI = tmpFilesTool.RootFolder.AddFile(FileName, FileDisplayName, contents);

            GrooveWebServicesV12Helpers.Files.File file = tmpFilesTool.RootFolder.OpenFile(fileURI);
            byte[] newContents = { (byte)'e', (byte)'f', (byte)'g', (byte)'h' };
            file.Update(FileName, FileDisplayName, newContents);

            Space.RemoveTool(tmpFilesTool.URI);
        }

        [Test()]
        [Description("Forms2 FormFileAttachment throws if no content")]
        public void Test_05_Forms2FormFileAttachmentTest()
        {
            //// cook up a space with a designed forms2 formstool and put a couple of records in it with/without attachments
            //string tmpSpaceURI = "/GWS/Groove/2.0/Spaces/grooveTelespace/r8wbdzshwp2krwhz6jiryh5mign3if23yebxw42";
            //GrooveWebServicesV12Helpers.Space tmpSpace = Identity.OpenSpace(tmpSpaceURI);

            GrooveWebServicesV12Helpers.Space tmpSpace = Space;

            GrooveWebServicesV12Helpers.Forms2.FormsTool formsTool = null;
            foreach (GrooveWebServicesV12Helpers.Tool tool in tmpSpace.Tools)
            {
                if (tool.Type == GrooveWebServicesV12Helpers.Shared.GROOVE_FORMS2_TOOL_SUPPORTED_TYPE)
                {
                    // you're going to find a discussion tool...
                    formsTool = (GrooveWebServicesV12Helpers.Forms2.FormsTool)tool;
                    break;
                }
            }

            Assert.IsNotNull(formsTool, "Forms Tool is Null");
            if (formsTool == null)
                throw new System.Exception("Forms Tool is null!");

            System.Data.DataSet dsNew = formsTool.Schema.ToDataSet();
            dsNew.EnforceConstraints = false;
            System.Data.DataTable table = dsNew.Tables[formsTool.Forms[0].SchemaID];

            // add a record with no attachment
            System.Data.DataRow newRow = table.NewRow();
            newRow["Forms_Tool_grooveFormID"] = formsTool.Forms[0].ID;
            newRow["Subject"] = "Without Attachment";
            table.Rows.Add(newRow);

            // add a record with an attachment
            System.Data.DataRow newRow2 = table.NewRow();
            newRow2["Forms_Tool_grooveFormID"] = formsTool.Forms[0].ID;
            newRow2["Subject"] = "With Attachment";
            // oops. I just realized, that's not implemented!
            //GrooveWebServicesV12Helpers.Forms2.FormFileAttachment attachment = 
            //attachment.FullName = "attachment1.txt";
            //attachment.Contents = new byte[] { (byte)'a', (byte)'b', (byte)'c' };
            //newRow2["Attachments"] = new GrooveWebServicesV12Helpers.Forms2.FormFileAttachment[] { attachment };
            table.Rows.Add(newRow2);

            dsNew.AcceptChanges();

            GrooveWebServicesV12Helpers.Forms2.RecordDataSet rds = new GrooveWebServicesV12Helpers.Forms2.RecordDataSet(dsNew);
            string[] newRecordURIs = formsTool.AddRecords(rds);

            // first, get the records with attachments
            System.Data.DataSet ds = formsTool.GetFormRecords(formsTool.Forms[0].URI, true).ToDataSet();
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                GrooveWebServicesV12Helpers.Forms2.FormFileAttachment[] attachments =
                    GrooveWebServicesV12Helpers.Forms2.FormFileAttachment.GetFormFileAttachments(row);
                foreach (GrooveWebServicesV12Helpers.Forms2.FormFileAttachment attachment in attachments)
                {
                    Console.WriteLine("Attachment - {0}", attachment.FullName);
                }
            }

            // then, get the records without attachments
            ds = formsTool.GetFormRecords(formsTool.Forms[0].URI, false).ToDataSet();
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                GrooveWebServicesV12Helpers.Forms2.FormFileAttachment[] attachments =
                    GrooveWebServicesV12Helpers.Forms2.FormFileAttachment.GetFormFileAttachments(row);
                foreach (GrooveWebServicesV12Helpers.Forms2.FormFileAttachment attachment in attachments)
                {
                    Console.WriteLine("Attachment - {0}", attachment.FullName);
                }
            }
        }

        bool m_SpaceAdded = false;
        bool m_SpaceRenamed = false;
        bool m_SpaceDeleted = false;
        string m_NewSpaceURI = null; 

        [Test()]
        [Description("EventManagerThreadProc deletes wrong number of Events")]
        public void Test_06_EventManagerThreadProcEventTest()
        {
            Identity.OnSpaceAddedEvent += new GrooveWebServicesV12Helpers.Identity.OnSpaceAddedDelegate(Identity_OnSpaceAddedEvent);
            Identity.OnSpaceRenamedEvent += new GrooveWebServicesV12Helpers.Identity.OnSpaceRenamedDelegate(Identity_OnSpaceRenamedEvent);
            Identity.OnSpaceRemovedEvent += new GrooveWebServicesV12Helpers.Identity.OnSpaceRemovedDelegate(Identity_OnSpaceRemovedEvent);

            m_NewSpaceURI = Identity.CreateSpace("Space Name", "Space Description");
            GrooveWebServicesV12Helpers.Space theSpace = Identity.OpenSpace(m_NewSpaceURI);

            theSpace.Update("New Space Name", "New Space Description");

            Console.WriteLine("Space Name={0}, Description={1}", theSpace.Name, theSpace.Description);

            DateTime StartTime = DateTime.Now;
            bool bTimedOut = false;
            Console.WriteLine("Sleeping");
            do
            {
                Console.Write(".");
                System.Threading.Thread.Sleep(500);

                System.TimeSpan TimeSpan = System.DateTime.Now.Subtract(StartTime);
                bTimedOut = TimeSpan.TotalSeconds > 10.0;

            } while ((!m_SpaceAdded || !m_SpaceRenamed) && !bTimedOut);

            Assert.IsTrue(m_SpaceAdded && m_SpaceRenamed, "Didn't get all events");

            Identity.DeleteSpace(m_NewSpaceURI, true, true);

            StartTime = DateTime.Now;
            bTimedOut = false;
            Console.WriteLine("Sleeping");
            do
            {
                Console.Write(".");
                System.Threading.Thread.Sleep(500);

                System.TimeSpan TimeSpan = System.DateTime.Now.Subtract(StartTime);
                bTimedOut = TimeSpan.TotalSeconds > 10.0;

            } while ((!m_SpaceDeleted) && !bTimedOut);

            Assert.IsTrue(m_SpaceAdded && m_SpaceRenamed && m_SpaceDeleted, "Didn't get all events");

            Identity.OnSpaceAddedEvent -= new GrooveWebServicesV12Helpers.Identity.OnSpaceAddedDelegate(Identity_OnSpaceAddedEvent);
            Identity.OnSpaceRenamedEvent -= new GrooveWebServicesV12Helpers.Identity.OnSpaceRenamedDelegate(Identity_OnSpaceRenamedEvent);
            Identity.OnSpaceRemovedEvent -= new GrooveWebServicesV12Helpers.Identity.OnSpaceRemovedDelegate(Identity_OnSpaceRemovedEvent);
        }

        void Identity_OnSpaceAddedEvent(GrooveWebServicesV12Helpers.Space i_Space)
        {
            if (m_NewSpaceURI == i_Space.URI)
            {
                m_SpaceAdded = true;
                Console.Write("OnSpaceAddedEvent");
            }
            else
            {
                Console.WriteLine("OnSpaceAddedEvent, m_NewSpaceURI={0}, i_Space.URI={1}", m_NewSpaceURI, i_Space.URI);
            }
        }

        void Identity_OnSpaceRenamedEvent(GrooveWebServicesV12Helpers.Space i_Space)
        {
            if (m_NewSpaceURI == i_Space.URI)
            {
                m_SpaceRenamed = true;
                Console.Write("OnSpaceRenamed");
            }
            else
            {
                Console.WriteLine("OnSpaceRenamed, m_NewSpaceURI={0}, i_Space.URI={1}", m_NewSpaceURI, i_Space.URI);
            }
        }

        void Identity_OnSpaceRemovedEvent(string i_SpaceURI)
        {
            if (m_NewSpaceURI == i_SpaceURI)
            {
                m_SpaceDeleted = true;
                Console.Write("OnSpaceRemoved");
            }
            else
            {
                Console.WriteLine("OnSpaceRemoved, m_NewSpaceURI={0}, i_SpaceURI={1}", m_NewSpaceURI, i_SpaceURI);
            }
        }

        [Test()]
        [Description("ContactDirectory throws exception if no matches")]
        public void Test_07_ContactDirectoryThrowsIfNoMatches()
        {
            string query = "Alfred.E.Neuman@Hotmail.com";

            foreach (GrooveWebServicesV12Helpers.ContactDirectory contactDirectory in Account.ContactDirectories)
            {
                Console.WriteLine("Directory={0}", contactDirectory.Name);

                GrooveWebServicesV12Helpers.ContactSummary[] contactSummaries = contactDirectory.Search(query);
                if (contactSummaries != null && contactSummaries.Length > 0)
                    Console.WriteLine("unbelievable");
            }
        }

        [Test()]
        [Description("Member Enter/Exit Space(), Enter/Exit Tool Test")]
        public void Test_08_MemberEnterExitSpaceTool()
        {
            GrooveWebServicesV12Helpers.ToolTemplate[] ToolTemplates = Space.ToolTemplates;

            GrooveWebServicesV12Helpers.ToolTemplate filesToolTemplate = null;
            foreach (GrooveWebServicesV12Helpers.ToolTemplate tt in ToolTemplates)
            {
                if (tt.Name == "Files")
                {
                    filesToolTemplate = tt;
                    break;
                }
            }

            Assert.IsNotNull(filesToolTemplate, "Null filesToolTemplate");
            string tmpFilesToolURI = Space.AddTool("Test File Update", filesToolTemplate);
            GrooveWebServicesV12Helpers.Files.FilesTool tmpFilesTool = (GrooveWebServicesV12Helpers.Files.FilesTool)Space.OpenTool(tmpFilesToolURI);

            GrooveWebServicesV12Helpers.Member aMember = Space.Members[0];

            aMember.EnterSpace();
            aMember.EnterTool(tmpFilesTool);
            aMember.ExitTool(tmpFilesTool);
            aMember.ExitSpace();
        }
    }
}
